<template>
<div class="block"  v-loading="loading">
		<div style="text-align: left;">
			<el-avatar :size="50" :src="userInfo.avatar"></el-avatar>
		</div>
		  <el-descriptions class="margin-top" title="个人信息" :column="2"  >
		    <template slot="extra">
		      <el-button type="primary" size="small" @click="userInfoCrud">操作</el-button>
		    </template>
		    <el-descriptions-item label="用户名">{{userInfo.username}}</el-descriptions-item>
		    <el-descriptions-item label="密碼">*******</el-descriptions-item>
		    <el-descriptions-item label="郵箱">{{userInfo.email}}</el-descriptions-item>
			<el-descriptions-item label="註冊日期">{{userInfo.created}}</el-descriptions-item>
			<el-descriptions-item label="最后登录">{{userInfo.lastLogin}}</el-descriptions-item>
		    <el-descriptions-item label="备注">
		      <el-tag size="small">超级管理员</el-tag>
		    </el-descriptions-item>
		  </el-descriptions>
		<!-- <table>
			<th><td>&nbsp;</td>
			<td>&nbsp;</td></th>
			<tr>
				<td>用戶名：</td>
				<td>{{userInfo.username}}</td>
			</tr>
			<tr>
				<td>密碼：</td>
				<td>*******</td>
			</tr>
			<tr>
				<td>郵箱：</td>
				<td>{{userInfo.email}}</td>
			</tr>
			<tr>
				<td>電話：</td>
				<td>{{userInfo.tel}}</td>
			</tr>
			<tr>
				<td>註冊日期：</td>
				<td>{{userInfo.created}}</td>
			</tr>
			<tr>
				<td>最后登录：</td>
				<td>{{userInfo.lastLogin}}</td>
			</tr>
			<tr>
				<td></td>
				<td>		<el-button type="danger" @click="logout()">退出登录</el-button></td>
			</tr>
		</table> -->
    </div>  
</template>

<script>
	export default{
		name:'UserInfo',
		data(){
			return{
				 loading:true,
				 userInfo: null,
			}
		},
		created() {
		  this.page(1)
		},
		  methods: {
			  userInfoCrud(){
				        this.$notify({
				          title: '警告',
				          message: '未开启修改权限，禁止操作',
				          type: 'warning'
				        });  
			  },
			  page(currentPage) {
				this.$axios.post("/user/index").then(res => {
					this.userInfo = res.data.data
					this.loading = false
					let time = this.userInfo.created.replace(/T/g,' ')
					let date = new Date(time);
					this.userInfo.created = date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
					time = this.userInfo.lastLogin.replace(/T/g,' ');
					date = new Date(time);
					this.userInfo.lastLogin = date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
				})
			  },
			  logout() {
			  			// 退出测试
			  			sessionStorage.removeItem("userInfo")
			  			  this.$router.push("/")
			  			  console.log("退出成功");
						
			  			const _this = this
			  			_this.$axios.get("/logout", {
			  			  headers: {
			  				"Authorization": localStorage.getItem("token")
			  			  }
			  			}).then(res => {
			  			  _this.$store.commit("REMOVE_INFO")
			  			  _this.$router.push("/login")
			  			})
						this.$router.go(0)
			  }
		 }
	} 
</script>

<style scoped>
	table td{
			  font-size: 14px;
	} 
	table .el-button{
		font-size: 14px;
	}
</style>
